package com.spzx.product.test;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.BaseEntity;

/**
 * MybatisPlus逆向工程生成器
 */
public class GenMP {

    public static void main(String[] args) {

        String MODULE_NAME = "product";

        FastAutoGenerator.create("jdbc:mysql://192.168.217.200:3306/spzx-"+ MODULE_NAME +"?characterEncoding=utf-8&useSSL=false", "root", "root")
                .globalConfig(builder -> builder
                        .author("spzx")// 设置作者
//                        .outputDir("G:/Java/Xvyy_Project_02/spzx-parent/spzx-modules/spzx-product/src/main/java")// 设置输出目录
                        .outputDir("G:/Java/Xvyy_Project_02/spzx-parent/spzx-modules")// 以免覆盖
                        .dateType(DateType.ONLY_DATE)// 设置日期类型 时间日期处理 使用java.until.Date
                        .disableOpenDir()// 设置不打开输出目录
//                        .enableSwagger()// 开启 swagger 模式
                )
                .packageConfig(builder -> builder
                        .parent("com.spzx." + MODULE_NAME)
                        .entity("domain")
                        .mapper("mapper")
                        .xml("mapper." + MODULE_NAME)
                        .service("service")
                        .serviceImpl("service.impl")
                        .controller("controller")
                )
                .strategyConfig(builder -> builder
                                .addInclude(
                                        "brand",
                                        "category",
                                        "category_brand",
                                        "product",
                                        "product_details",
                                        "product_sku",
                                        "product_spec",
                                        "product_unit",
                                        "sku_stock") // 设置需要生成的表名
                                .entityBuilder()// 设置实体类
                                .enableLombok()// 设置lombok
                                .superClass(BaseEntity.class)// 设置继承的父类
                                .addSuperEntityColumns(// 设置父类中共同的字段
                                        "id",
                                        "create_by",
                                        "create_time",
                                        "update_by",
                                        "update_time",
                                        "remark",
                                        "del_flag")
                                //.addIgnoreColumns
                                .enableFileOverride()// 设置覆盖已有文件

                                .serviceBuilder()// 设置service
                                .formatServiceFileName("%sService")// 设置service接口名称格式
                                .enableFileOverride()// 设置覆盖已有文件

                                .controllerBuilder()// 设置controller
                                .superClass(BaseController.class)// 设置继承的父类
                                .enableRestStyle()// 设置rest风格 @RestController
                                .enableFileOverride()// 设置覆盖已有文件
                )
                .templateEngine(new FreemarkerTemplateEngine())// 设置自定义配置
                .execute();// 执行
    }
}